package com.brodong.animal_remake;

import com.brodong.animal_remake.common.entities.monster.realization.GeckoTestEntity;
import com.brodong.animal_remake.common.registers.EntityRegister;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Biomes;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.registries.RegistryObject;
import org.jetbrains.annotations.NotNull;

import javax.xml.crypto.Data;
import java.util.*;

public class Config {
    public static class Data<T extends Entity>{
        public String name="";
        public RegistryObject<EntityType<T>> MOB=null;
        public ForgeConfigSpec.ConfigValue<String> Config=null;
        public Data(String na,RegistryObject<EntityType<T>> mo,ForgeConfigSpec.ConfigValue<String> Con){
            name=na;
            MOB=mo;
            Config=Con;
        }
    }
    public static class ReadData{
        public int weight,minCount,maxCount;
        public ResourceKey<Biome> biome;
        public ReadData(ResourceKey<Biome> B,int w, int min, int max){
            weight=w;minCount=min;maxCount=max;biome=B;
        }
    }
    public static ForgeConfigSpec commonConfig;
    public static boolean ReadData=false;
    public static ArrayList<Data> Config = new ArrayList();
    public static HashMap<String,ResourceKey<Biome>> FindBiomes=new HashMap<>();
    public static ArrayList<ReadData> whitelistStrtoArraylist(ForgeConfigSpec.ConfigValue<String> Basewhitelist)
    {
        ArrayList<ReadData> whiteArraylist = new ArrayList<>();
        if(Basewhitelist==null)return whiteArraylist;
        String whitelist = Basewhitelist.get();
        String[] whiteBiomes = whitelist.split(";");
        for (String whiteBiome:whiteBiomes) {
            if(!whiteBiome.isEmpty())
            {
                String[] Rddata=whiteBiome.split(",");
                if(Rddata.length==4&&FindBiomes.get(Rddata[0])!=null){
                    whiteArraylist.add(new ReadData(FindBiomes.get(Rddata[0]),Integer.parseInt(Rddata[1]),Integer.parseInt(Rddata[2]),Integer.parseInt(Rddata[3])));
                }
            }
        }
        return whiteArraylist;
    };
    static {
        FindBiomes.put("the_void", Biomes.THE_VOID);
        FindBiomes.put("plains", Biomes.PLAINS);
        FindBiomes.put("sunflower_plains", Biomes.SUNFLOWER_PLAINS);
        FindBiomes.put("snowy_plains", Biomes.SNOWY_PLAINS);
        FindBiomes.put("ice_spikes", Biomes.ICE_SPIKES);
        FindBiomes.put("desert", Biomes.DESERT);
        FindBiomes.put("swamp", Biomes.SWAMP);
        FindBiomes.put("forest", Biomes.FOREST);
        FindBiomes.put("flower_forest", Biomes.FLOWER_FOREST);
        FindBiomes.put("birch_forest", Biomes.BIRCH_FOREST);
        FindBiomes.put("dark_forest", Biomes.DARK_FOREST);
        FindBiomes.put("old_growth_birch_forest", Biomes.OLD_GROWTH_BIRCH_FOREST);
        FindBiomes.put("old_growth_pine_taiga", Biomes.OLD_GROWTH_PINE_TAIGA);
        FindBiomes.put("old_growth_spruce_taiga", Biomes.OLD_GROWTH_SPRUCE_TAIGA);
        FindBiomes.put("taiga", Biomes.TAIGA);
        FindBiomes.put("snowy_taiga", Biomes.SNOWY_TAIGA);
        FindBiomes.put("savanna", Biomes.SAVANNA);
        FindBiomes.put("savanna_plateau", Biomes.SAVANNA_PLATEAU);
        FindBiomes.put("windswept_hills", Biomes.WINDSWEPT_HILLS);
        FindBiomes.put("windswept_gravelly_hills", Biomes.WINDSWEPT_GRAVELLY_HILLS);
        FindBiomes.put("windswept_forest", Biomes.WINDSWEPT_FOREST);
        FindBiomes.put("windswept_savanna", Biomes.WINDSWEPT_SAVANNA);
        FindBiomes.put("jungle", Biomes.JUNGLE);
        FindBiomes.put("sparse_jungle", Biomes.SPARSE_JUNGLE);
        FindBiomes.put("bamboo_jungle", Biomes.BAMBOO_JUNGLE);
        FindBiomes.put("badlands", Biomes.BADLANDS);
        FindBiomes.put("eroded_badlands", Biomes.ERODED_BADLANDS);
        FindBiomes.put("wooded_badlands", Biomes.WOODED_BADLANDS);
        FindBiomes.put("meadow", Biomes.MEADOW);
        FindBiomes.put("grove", Biomes.GROVE);
        FindBiomes.put("snowy_slopes", Biomes.SNOWY_SLOPES);
        FindBiomes.put("frozen_peaks", Biomes.FROZEN_PEAKS);
        FindBiomes.put("jagged_peaks", Biomes.JAGGED_PEAKS);
        FindBiomes.put("stony_peaks", Biomes.STONY_PEAKS);
        FindBiomes.put("river", Biomes.RIVER);
        FindBiomes.put("frozen_river", Biomes.FROZEN_RIVER);
        FindBiomes.put("beach", Biomes.BEACH);
        FindBiomes.put("snowy_beach", Biomes.SNOWY_BEACH);
        FindBiomes.put("stony_shore", Biomes.STONY_SHORE);
        FindBiomes.put("warm_ocean", Biomes.WARM_OCEAN);
        FindBiomes.put("lukewarm_ocean", Biomes.LUKEWARM_OCEAN);
        FindBiomes.put("deep_lukewarm_ocean", Biomes.DEEP_LUKEWARM_OCEAN);
        FindBiomes.put("ocean", Biomes.OCEAN);
        FindBiomes.put("deep_ocean", Biomes.DEEP_OCEAN);
        FindBiomes.put("cold_ocean", Biomes.COLD_OCEAN);
        FindBiomes.put("deep_cold_ocean", Biomes.DEEP_COLD_OCEAN);
        FindBiomes.put("frozen_ocean", Biomes.FROZEN_OCEAN);
        FindBiomes.put("deep_frozen_ocean", Biomes.DEEP_FROZEN_OCEAN);
        FindBiomes.put("mushroom_fields", Biomes.MUSHROOM_FIELDS);
        FindBiomes.put("dripstone_caves", Biomes.DRIPSTONE_CAVES);
        FindBiomes.put("lush_caves", Biomes.LUSH_CAVES);
        FindBiomes.put("nether_wastes", Biomes.NETHER_WASTES);
        FindBiomes.put("warped_forest", Biomes.WARPED_FOREST);
        FindBiomes.put("crimson_forest", Biomes.CRIMSON_FOREST);
        FindBiomes.put("soul_sand_valley", Biomes.SOUL_SAND_VALLEY);
        FindBiomes.put("basalt_deltas", Biomes.BASALT_DELTAS);
        FindBiomes.put("the_end", Biomes.THE_END);
        FindBiomes.put("end_highlands", Biomes.END_HIGHLANDS);
        FindBiomes.put("end_midlands", Biomes.END_MIDLANDS);
        FindBiomes.put("small_end_islands", Biomes.SMALL_END_ISLANDS);
        FindBiomes.put("end_barrens", Biomes.END_BARRENS);
        ForgeConfigSpec.Builder commonBuilder = new ForgeConfigSpec.Builder();
        commonBuilder.push("SummerWhitelists");
        commonBuilder.push("SuchAs : plains,10,1,2;desert,10,1,2");
        String s;
        s="GECKO_TEST";Config.add(new Data(s,EntityRegister.GECKO_TEST,commonBuilder.comment("Whitelist for "+s+", use ',' and ';' to split").define(s+"Whitelist","")));
        s="MELEE_BASIC";Config.add(new Data(s,EntityRegister.MELEE_BASIC,commonBuilder.comment("Whitelist for "+s+", use ',' and ';' to split").define(s+"Whitelist","")));
        s="FLYING_RANGE_BASIC";Config.add(new Data(s,EntityRegister.FLYING_RANGE_BASIC,commonBuilder.comment("Whitelist for "+s+", use ',' and ';' to split").define(s+"Whitelist","")));
        s="REMOTE_BASIC";Config.add(new Data(s,EntityRegister.REMOTE_BASIC,commonBuilder.comment("Whitelist for "+s+", use ',' and ';' to split").define(s+"Whitelist","")));
        s="WITCH_BASIC";Config.add(new Data(s,EntityRegister.WITCH_BASIC,commonBuilder.comment("Whitelist for "+s+", use ',' and ';' to split").define(s+"Whitelist","")));
        s="FLY_MELEE_BASIC";Config.add(new Data(s,EntityRegister.FLY_MELEE_BASIC,commonBuilder.comment("Whitelist for "+s+", use ',' and ';' to split").define(s+"Whitelist","")));
        s="SKILL_BASIC";Config.add(new Data(s,EntityRegister.SKILL_BASIC,commonBuilder.comment("Whitelist for "+s+", use ',' and ';' to split").define(s+"Whitelist","")));
        commonBuilder.pop();
        commonConfig = commonBuilder.build();
    }
}
